package Deliver;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

import Bfs.Bfs;
import Bfs.Car;

public class Delivery {

	Bfs bfs;
	ArrayList<String> cRoute;
	
	public Delivery(Bfs bfs)
	{		
		this.bfs=bfs;
	}

	public void deliver(String dest, Car car)
	{
		cRoute = stringToArray(car.getCurrentRoute());
		if(!cRoute.contains(dest)) 
		{
			
			car.setCurrentRoute(car.getCurrentRoute()+","+car.routeToString(bfs.bfs(cRoute.get(cRoute.size()-1), dest)));
			//path goes to destination is added to car's current route
			
		}
		
		/*else
		 * 
		 *  //Destination is already inside the current path of car.
		 *  
		 * */
	}
	
	//Car's current route will be retrieved from the database as String with comma separator.
	//We convert it to ArrayList to use easily.
	public ArrayList<String> stringToArray(String currentRoute)
	{
		ArrayList<String> cRoute = new ArrayList<String>(Arrays.asList(currentRoute.split(",")));
		return cRoute;
		
	}
	
}
